package com.example.administrator.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016/3/17 0017.
 */
public class AppListAdapter extends BaseAdapter{
    //正在运行进程的ListView适配器
    private LayoutInflater mInflater;
    private List<Program> mList;
    public AppListAdapter(Context context, List<Program> list){
        mList = list;
        mInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = new ViewHolder();
        if(convertView == null){
            convertView = mInflater.inflate(R.layout.list_item_app,null);
            viewHolder.icon = (ImageView) convertView.findViewById(R.id.app_img);
            viewHolder.name = (TextView) convertView.findViewById(R.id.app_name);
            convertView.setTag(viewHolder);
        }
        else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Program program = mList.get(position);
        //动态赋值
        viewHolder.icon.setImageDrawable(program.getmIcon());
        viewHolder.name.setText(program.getmName());
        return convertView;
    }
    class ViewHolder{
        public ImageView icon;
        public TextView name;
    }
}
